//
//  BaseTableViewController.swift
//  01-微博项目搭建
//
//  Created by Adolph on 15/5/14.
//  Copyright (c) 2015年 Adolph. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {
    
    //记录用户是否已经登入
    let userLogin = sharedUserAccount != nil
    /// 访客登录视图
    var visitorLoginView: VisitorLoginView?
    override func loadView() {
        
        selectView()
    }  
    
    ///判断第一次加载视图
    func selectView(){
        if userLogin {
            super.loadView()
            return
        }
        
        visitorLoginView = NSBundle.mainBundle().loadNibNamed("VisitorLoginView", owner: nil, options: nil).last as? VisitorLoginView
        
        visitorLoginView?.delegate = self
        view = visitorLoginView
        
        //添加导航栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didSelectedRegisterButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登入", style: UIBarButtonItemStyle.Plain, target: self, action: "didSelectedLoginButton")
    }
    
    func didSelectedLoginButton() {
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        presentViewController(sb.instantiateInitialViewController() as! UIViewController, animated: true, completion: nil)
        
    }
    func didSelectedRegisterButton() {
        println(__FUNCTION__)
    }
   
}
